//implement GThread
//andycai_sc 2011-04-29

#include "GParallel/GThreadImpl.h"

GThread::GThread()
{
	m_threadImpl = GThreadImplCreator::create(this);
}

GThread::~GThread()
{
	if (m_threadImpl != 0)
		delete m_threadImpl;
}

void GThread::start()
{
	m_threadImpl->startImpl();
}

void GThread::stop()
{
	m_threadImpl->stopImpl();
	join();
}

void GThread::join()
{
	m_threadImpl->joinImpl();
}

void GThread::sleep(long mseconds)
{
    (*GThreadImpl::_sleepImpl)(mseconds);
}

GThreadImpl* GThreadImplCreator::create(GThread* _thread)
{
#if (defined(USE_ACE_ALL) && !defined(NO_ACE_THREAD)) || defined(USE_ACE_THREAD)
    return createThreadFromAce(_thread);
#elif (defined(USE_BOOST_ALL) && !defined(NO_BOOST_THREAD)) || defined(USE_BOOST_THREAD)
    return createThreadFromBoost(_thread);
#elif (defined(USE_POCO_ALL) && !defined(NO_POCO_THREAD)) || defined(USE_POCO_THREAD)
    return createThreadFromPoco(_thread);
#elif (defined(USE_QT_ALL) && !defined(NO_QT_THREAD)) || defined(USE_QT_THREAD)
    return createThreadFromQt(_thread);
#elif (defined(USE_STL_ALL) && !defined(NO_STL_THREAD)) || defined(USE_STL_THREAD)
	return createThreadFromStl(_thread);
#else
    return createThreadFromGToy(_thread);
#endif
}
